package com.cicv.oss.config.adapter.controller;

import com.cicv.oss.config.adapter.entity.OssConfigInfo;
import com.cicv.oss.config.infra.config.OssConfig;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/oss")
public class OssController {
    @Resource
    private OssConfig ossConfig;

    /**
     * endpoint: "http://open-bucket.oss.icvdc.com"
     * access-key-id:
     * access-key-secret:
     * bucket-name:
     *
     * @param token
     * @return
     */
    @GetMapping("/config")
    public OssConfigInfo config(@RequestParam("token") String token) {
        if ("nXonLUcMtGcrQqqKiyygIwyVbvizE0wD".equals(token)) {
            return new OssConfigInfo(
                    ossConfig.getEndpoint(),
                    ossConfig.getAccessKeyId(),
                    ossConfig.getAccessKeySecret(),
                    ossConfig.getBucketName()
            );
        } else {
            return null;
        }
    }


}
